<?php
/**
 * @Notes:【】
 * @Date: 2022-06-09 22:17
 */

namespace App\Task;

use App\Service\Task\TaskReceiveService;
use App\Service\Task\TaskService;
use Hyperf\Config\Annotation\Value;
use Hyperf\Crontab\Annotation\Crontab;
use Hyperf\Di\Annotation\Inject;

#[Crontab(name: "Foo", rule: "* * * * * *", callback: "execute", memo: "这是一个示例的定时任务")]
class TaskCancel
{
    /**
     * @Inject()
     * @var TaskReceiveService
     */
    protected $taskReceiveService;

    public function execute()
    {

        $data = $this->taskReceiveService->taskRevicesDao
            ->whereIn('status', [0, 2])
            ->where('cancel_time', '<', time())->first();

        if ($data) {
            $this->taskReceiveService->cancel(_Collect([
                'taskReceiveid' => $data->id,
                'user_id' => $data->user_id
            ]));
        }

    }
}